
#include "../common/stdafx.h"

#include "Machine\MachineBase.h"

QuizMachine quizMachine;
RaceMachine raceMachine;

glm::ivec2 SCREEN_SIZE(1280,480);

static void key_callback(GLFWwindow* window,int key,int scancode,int action,int mods)
{
	if(key== GLFW_KEY_ESCAPE && action == GLFW_PRESS)
		glfwSetWindowShouldClose(window,GL_TRUE);

	if(action == GLFW_PRESS)
	{
		quizMachine.InputKeyHandler(key);
	}
		
}

int main(int argc , char* argv[])
{
	GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
	window = glfwCreateWindow(SCREEN_SIZE.x, SCREEN_SIZE.y, "Test", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);
	glfwSetKeyCallback(window,key_callback);

	// Initialize GLEW
	glewExperimental = true;
	if(glewInit() != GLEW_OK)
	{
		fprintf(stderr,"Failed to initialize GLEW\n");
		return -1;
	}
	
	SceneRender* sceneRender = new SceneRender();
	quizMachine.Init();
	raceMachine.Init();
	sceneRender->Init();

	quizMachine.SetRender(sceneRender);
	raceMachine.SetRender(sceneRender);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
		raceMachine.Run();
		quizMachine.Run();

		sceneRender->Render();

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;

}